//
//  UIButton+NavButton.m
//  LPSNews
//
//  Created by Ruan on 14-10-9.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "UIButton+NavButton.h"

@implementation UIButton (NavButton)

// 导航条的按钮分类
+ (UIButton *)addNavButtonWithNormalImageString:(NSString *)normalImageString andHeightLightedImageString:(NSString *)heightLightedImageString
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setImage:[UIImage imageNamed:normalImageString] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:heightLightedImageString] forState:UIControlStateHighlighted];
    CGSize buttonImageSize = [button currentImage].size;
    button.frame = (CGRect){CGPointZero,buttonImageSize};
    return button;
    
}


// 左侧控制面板按钮的分类
+ (UIButton *)addRootViewButtonWithNormalTitilString:(NSString *)normalTitilString
{
    UIButton *boutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [boutton setTitle:normalTitilString forState:UIControlStateNormal];
    [boutton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    boutton.titleLabel.font = [UIFont systemFontOfSize:18];
    boutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

    
    return boutton;
}

// 重写高亮方法


+(UIImage *)scaleToSizeImage:(UIImage *)image size:(CGSize)size
{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(size);
    
    // 绘制改变大小的图片
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    
    // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    
    // 返回新的改变大小后的图片
    return scaledImage;
}
//img为网上下载的图片
//size 为按钮的大小 这个函数返回转换之后的IMAGE


+ (UIButton *)buttonAddNewsNavBarButtonWithTitle:(NSString *)title
{
    UIButton *newsTopButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [newsTopButton setTitle:title forState:UIControlStateNormal];
    [newsTopButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    newsTopButton.titleLabel.font = [UIFont systemFontOfSize:14];
    return newsTopButton;
}









@end